Macromedia Flex Article

Learning Flex Basics (Part 1): Creating Your First Flex Application


Table of Contents

  1. Introduction
  2. A Brief Overview of Macromedia Flex
  3. Building the Application
  4. Create the Application Object
  5. Add a Panel for the Application Layout
  6. Add a Label for the View Header
  7. Add an Array of Objects to Define the Coffee Blends
  8. Add a ComboBox to Display the Coffee Blends
  9. Add a Text Control to Display the Description
  10. Add a Button to Add a Coffee Blend to the Shopping Cart
  11. Add a List Control for the Shopping Cart
  12. Add a Script to Handle the Button Click Event
  13. Complete Code Listing for firstapp.mxml
  14. Where to Go From Here

Add an Array of Objects to Define the Coffee Blends

The data model for this application is an array of objects that you build directly into the application using the Array and Object elements. Each of the objects has two properties, label and data, which you define as subtags in the Objects. This data structure corresponds to the dataProvider form used by controls like the ComboBox and List, which you use later in this tutorial.

These controls can use more complex data objects, but since you build the data model manually here, you use the simple form. The general syntax you use is:

<mx:Array id="identifier">
  <mx:Object>
      <label>literal string</label>
      <data>another literal string</data>
  </mx:Object>
</mx:Array>

The id attribute is available for nearly all Flex classes, and you use it to provide a unique identifier for an instance of the class. You need not provide an explicit id value unless you plan to refer to the object in data bindings or ActionScript.

Placement of faceless elements such an array is up to you, but it is good practice to place them the top of the application, above visual elements.

  1. Inside the Application block, before the Panel, add the following array of objects:
<mx:Array id="coffeeArray">
	<mx:Object>
		<label>Red Sea</label>
		<data>Smooth and fragrant</data>
	</mx:Object>
	<mx:Object>
		<label>Andes</label>
		<data>Rich and pungent</data>
	</mx:Object>
	<mx:Object>
	<label>Blue Mountain</label>
	<data>Delicate and refined</data>
	</mx:Object>
</mx:Array>